<%@ page import="vy.org.app.common.*" %>
<%@ page import="org.vy.dal.dao.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.vy.dal.dao.lookup.ViewVyLookupCitiesDO" %>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>

<%!
	private static final String EMPTY = "";
	private UserCtx m_user;
%>

<%
	ResourceBundle RESOURCE = ResourceBundle.getBundle("LabelResource",ActionCtx.ctx().getLocale());

	m_user = ActionCtx.ctx(request).getUser();
  	boolean canAdd = m_user.hasAccessToModule(ModuleEnum.ADD_MEMBER.getId().toString());
  	boolean canDelete = m_user.hasAccessToModule(ModuleEnum.DELETE_MEMBER.getId().toString());
  	boolean canEdit = m_user.hasAccessToModule(ModuleEnum.EDIT_MEMBER.getId().toString());
  	boolean editSubscription = m_user.hasAccessToModule(ModuleEnum.EDIT_SUBSCRIPTION.getId().toString());
%>
<bean:define id="mntnMemberForm" name="mntnMemberForm" scope="request" type="vy.org.app.page.member.MntnMemberForm"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
	<link rel="stylesheet" type="text/css" href="./css/Common.css">
	<script type="text/javascript" src="./scripts/Common.js"></script>
	<script type="text/javascript" src="./scripts/validateForm.js"></script>
	<script type="text/javascript" src="./scripts/KrutidevUnicode.js"></script>
<script type="text/javascript">
function checkFields(){
	var flag = true;
	if(!checkChar('name',"Name"))
			flag=false;
	else if(!checkInt('mobileNumber',"Mobile"))
		flag=false;
	else if(!checkInt('workPhone',"Business/Work Phone"))
		flag=false;
	else if(!checkInt('homePhone',"HomePhone"))
		flag=false;
	else if(!checkEmail('email',"Email"))
		flag=false;
	else if(!checkChar('districtOrCounty',"District"))
		flag=false;
		
	
	return flag;
}

</script>

</head> 
<body>
<form name="mntnMemberForm" onSubmit="return checkFields();"method=post action="./mntnmember.do">
  <input type="hidden" name="mode" id="mode" value="SEARCH">
  <input type="hidden" name="lang" id="lang" value="<%=ActionCtx.ctx().getLang() %>">
  <table class="qry" width="100%" border="0" cellspacing="1" cellpadding="0">
    <tr>
      <td></td>
      <td><img src="./pages/image_gif/mf1.gif" width="100%" height="35"></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td style="text-align:right;width:850px;display:none;">
      	<a id="kruti" class="alang" href="javascript:;"><%=RESOURCE.getString(AppConstants.Languages.KRUTI) %></a>
      	<a id="hindi" class="alang" href="javascript:;"><%=RESOURCE.getString(AppConstants.Languages.HINDI) %></a>
      	<a id="english" class="alang" href="javascript:;"><%=RESOURCE.getString(AppConstants.Languages.ENGLISH) %></a>
      </td>
      <td></td>
    </tr>
    <tr>
      <td align="right" valign="middle" width="3" ></td>
      <td width="850px"  align="left" valign="top">
      <noscript><div class="err">Kindly enable javascript in your browser</div></noscript> 
      	<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
          <tr>
            <td height="24" colspan="4">
            	<table width="100%" border="0" cellpadding="0" cellspacing="0">
            	<tr>
              		<td height="22"><img src="./pages/image_gif/search_mem.gif" alt="" name="off_add" width="100%" height="22" border="0" ></td>
              	</tr>
            	</table>
            </td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td width="20%"><div align="left"><strong>&nbsp;<%=RESOURCE.getString("VY_ID") %></strong> &nbsp;</div></td>
            <td width="30%"><input name="vyId" type="text" class="textBoxDashed" id="vyId" size="33" maxlength="50" value="<bean:write name='mntnMemberForm' property='vyId' />"></td>
            <td width="20%" colspan="2"><!-- div align="right">< % = RESOURCE.getString("FAMILY_VY_ID") % > </div></td>
            <td width="30%"><input name="familyVyId" type="text" class="textBoxDashed" id="familyVyId" size="33" maxlength="15" value="< bean : write name='mntnMemberForm' property='familyVyId' / >" --></td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td width="20%"><div align="left">&nbsp;<%=RESOURCE.getString("NAME") %></div></td>
            <td width="30%"><input name="name" type="text" class="textBoxDashed" id="name" size="33" maxlength="100" value="<bean:write name='mntnMemberForm' property='name' />"></td>
            <td width="20%"><div align="left">&nbsp;<%=RESOURCE.getString("REGIONAL_LANG_NAME") %></div></td>
            <td width="30%"><input name="regionalLangName" type="text" class="kd010" id="regionalLangName" size="33" maxlength="200" value="<bean:write name='mntnMemberForm' property='regionalLangName' />"></td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td width="20%"><div align="left">&nbsp;<%=RESOURCE.getString("MOBILE") %></div></td>
            <td width="30%"><input name="mobileNumber" type="text" class="textBoxDashed" id="mobileNumber" size="33" maxlength="20" value="<bean:write name='mntnMemberForm' property='mobileNumber' />"></td>
            <td width="20%"><div align="left">&nbsp;<%=RESOURCE.getString("HOME_PHONE") %></div></td>
            <td width="30%"><input name="homePhone" type="text" class="textBoxDashed" id="homePhone" size="33" maxlength="20" value="<bean:write name='mntnMemberForm' property='homePhone' />"></td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td><div align="left">&nbsp;<%=RESOURCE.getString("WORK_PHONE") %></div></td>
            <td><input name="workPhone" type="text" class="textBoxDashed" id="workPhone" size="33" maxlength="20" value="<bean:write name='mntnMemberForm' property='workPhone' />"></td>
            <td><div align="left">&nbsp;<%=RESOURCE.getString("EMAIL") %></div></td>
            <td><input name="email" type="text" class="textBoxDashed" id="email" size="33" maxlength="200" value="<bean:write name='mntnMemberForm' property='email' />"></td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td><div align="left">&nbsp;<%=RESOURCE.getString("ADDRESS") %></div></td>
            <td><input name="address" type="text" class="textBoxDashed" id="address" size="33" maxlength="255" value="<bean:write name='mntnMemberForm' property='address' />"></td>
            <td><div align="left">&nbsp;<%=RESOURCE.getString("HINDI_ADDRESS") %></div></td>
            <td><input name="hindiAddress" type="text" class="kd010" id="hindiAddress" size="33" maxlength="255" value="<bean:write name='mntnMemberForm' property='hindiAddress' />"></td>
          </tr>

          <tr bgcolor="#EBEBEB">
            <td><div align="left">&nbsp;<%=RESOURCE.getString("UPDESTHA") %></div></td>
            <td>
            	<input name="isUpdestha" type="radio" id="isUpdestha" <%=("true".equals(mntnMemberForm.getIsUpdestha())? "checked" :"" ) %> value="true">&nbsp;<%=RESOURCE.getString("YES")%>
            	<input name="isUpdestha" type="radio" id="isUpdestha" <%=("false".equals(mntnMemberForm.getIsUpdestha())? "checked" :"" )%> value="false">&nbsp;<%=RESOURCE.getString("NO") %>
            	<input name="isUpdestha" type="radio" id="isUpdestha" <%=("both".equals(mntnMemberForm.getIsUpdestha()) || mntnMemberForm.getIsUpdestha()==null? "checked" :"" )%> value="both">&nbsp;<%=RESOURCE.getString("BOTH") %>
            </td>
            <td><div align="left">&nbsp;<%=RESOURCE.getString("DISTRICT_OR_COUNTY") %></div></td>
            <td>
            	<!--select name="districtOrCounty" id="districtOrCounty">
					<option selected value="">Select</option>
			  	</select-->
			  	<input type="text" name="districtOrCounty" id="districtOrCounty" value="<bean:write name='mntnMemberForm' property='districtOrCounty' />" >
			</td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td><div align="left">&nbsp;<%=RESOURCE.getString("COUNTRY") %></div>
			</td>
            <td>
              <select name="country" id="country">
                <option value="" >Select</option>
			  	<%
		  		if(mntnMemberForm.getCountries() != null){
			  		for(ViewVyLookupCitiesDO prcountry: mntnMemberForm.getCountries()){
			  			if(prcountry.getCountryCode().equals(mntnMemberForm.getCountry()))
			  				out.println("<option selected=\"selected\" value=\""+ prcountry.getCountryCode() +"\">"+ prcountry.getCountryName() +"</option>");
			  			else
			  				out.println("<option value=\""+ prcountry.getCountryCode() +"\">"+ prcountry.getCountryName() +"</option>");
			  		}
		  		}
			  	%>
              </select>
            </td>
            <td><div align="left">&nbsp;<%=RESOURCE.getString("RECEIPT_NO") %></div>
			</td>
			<td>
			  	<input type="text" name="receiptNo" id="receiptNo" value="<bean:write name='mntnMemberForm' property='receiptNo' />" >
            </td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td><div align="left">&nbsp;<%=RESOURCE.getString("STATE_OR_REGION") %></div>
			</td>
            <td colspan="3">
            	<select name="stateOrRegion" id="stateOrRegion">
					<option selected value="">Select</option>
			  	<%
		  		if(mntnMemberForm.getStates() != null){
			  		for(ViewVyLookupCitiesDO prstate: mntnMemberForm.getStates()){
			  			if(prstate.getStateCode().equals(mntnMemberForm.getStateOrRegion()))
			  				out.println("<option selected=\"selected\" value=\""+ prstate.getStateCode() +"\">"+ prstate.getStateName() +"</option>");
			  			else
			  				out.println("<option value=\""+ prstate.getStateCode() +"\">"+ prstate.getStateName() +"</option>");
			  		}
		  		}
			  	%>
			  	</select>
            </td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td><div align="left">&nbsp;<%=RESOURCE.getString("CITY") %></div>
			</td>
            <td colspan="3">
            	<select name="city" id="city">
                	<option selected value="">Select</option>
				  	<%
			  		if(mntnMemberForm.getCities() != null){
				  		for(ViewVyLookupCitiesDO prcity: mntnMemberForm.getCities()){
				  			if(prcity.getCityCode().equals(mntnMemberForm.getCity()))
				  				out.println("<option selected=\"selected\" value=\""+ prcity.getCityCode() +"\">"+ prcity.getCityName() +"</option>");
				  			else
				  				out.println("<option value=\""+ prcity.getCityCode() +"\">"+ prcity.getCityName() +"</option>");
				  		}
			  		}
				  	%>
              	</select>
            </td>
          </tr>
          <!--tr bgcolor="#EBEBEB">
            <td><div align="right">< % =RESOURCE.getString("CITY") % ></div></td>
            <td><input name="city" type="text" class="textBoxDashed" id="city" size="33" maxlength="150" value="< bean : write name='mntnMemberForm' property='city' />"></td>
            <td><div align="right">< % =RESOURCE.getString("DISTRICT_OR_COUNTY") % ></div></td>
            <td><input name="districtOrCounty" type="text" class="textBoxDashed" id="districtOrCounty" size="33" maxlength="150" value="< bean : write name='mntnMemberForm' property='districtOrCounty' />"></td>
          </tr>
          <tr bgcolor="#EBEBEB">
            <td><div align="right">< % =RESOURCE.getString("STATE_OR_REGION") % ></div></td>
            <td><input name="stateOrRegion" type="text" class="textBoxDashed" id="stateOrRegion" size="33" maxlength="150" value="< bean : write name='mntnMemberForm' property='stateOrRegion' />"></td>
            <td><div align="right">< % =RESOURCE.getString("COUNTRY") % ></div></td>
            <td><input name="country" type="text" class="textBoxDashed" id="country" size="33" maxlength="150" value="< bean : write name='mntnMemberForm' property='country' />"></td>
          </tr-->
          <tr bgcolor="#EBEBEB">
            <td colspan="4"><div align="center">
                <input type="reset" name="clear" value="  <%=RESOURCE.getString("CLEAR") %>  " class="btn" />
              &nbsp;&nbsp;
                <input name="search" type="submit" value="<%=RESOURCE.getString("SEARCH") %>" class="btn"/></div></td>
          </tr>
        </table>
         </td>
      <td></td>
    </tr>
    <tr>
      <td colspan="3"></td>
    </tr>
  </table>
  
  <div class="abtn-cnt">
  <%
  	if(canAdd){
  		%><a href="<%=ModuleEnum.ADD_MEMBER.getUrl() %>" name="add" class="abtn" title="Add Member"><%=RESOURCE.getString("ADD") %></a><%
  	}
	if(canDelete){
  		%><a href="javascript:;" id="adelete" name="adelete" class="abtn" title="Delete Member"><%=RESOURCE.getString("DELETE") %></a><%
  	}
//	if(editSubscription){
// 		% > <a href="javascript:;" id="agroupPrintLabel" name="agroupPrintLabel" class="abtn" title="Group Print Label" onclick="groupPrintLabel();"><%=RESOURCE.getString("GROUP_PRINT_LABEL") % ></a>< %
//  }
  %>
  </div>
  <div class="rst-panel" style="width:auto;">  
  <table class="rst" cellpadding="0" cellspacing="0" width="100%" border="0">
  	<thead>
  		<tr>
  			<th><div class="hd"><%=RESOURCE.getString("SELECT") %></div></th>
  			<th><div class="hd"><%=EMPTY %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("VY_ID") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("FIRST_NAME") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("MIDDLE_NAME") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("LAST_NAME") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("CITY") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("DISTRICT_OR_COUNTY") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("STATE_OR_REGION") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("COUNTRY") %></div></th>
  			<%
  				if(mntnMemberForm.getReceiptNo() != null && !"".equals(mntnMemberForm.getReceiptNo())){
  					%><th><div class="hd"><%=RESOURCE.getString("RECEIPT_NO") %></div></th><%
  				}
  			%>
  			<th><div class="hd"><%=RESOURCE.getString("REF_VY_ID") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("FAMILY_VY_ID") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("FAMILY_REF_TYPE") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("DATE_OF_BIRTH") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("CONTACT") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("EMAIL") %></div></th>
  		</tr>
  	</thead>
  	<tbody>
  <%
  	if(request.getAttribute(AppConstants.RESULT) != null){
  		List<ViewVyMemberDO> results = (List<ViewVyMemberDO>)request.getAttribute(AppConstants.RESULT);
  		int idx=0;
  		for(ViewVyMemberDO rec : results){
  			%><tr><%
			if(canDelete){
				%><td><input type="checkbox" name="members" value="<%=rec.getVyId() %>" /></td> <%
			}else{
				%><td><%=EMPTY %></td><%
			}
			if(rec.getIsDeleted()){
				%><td><img src="./images/iconError_16x16.gif" border="0" /></td> <%
			}else{
				%><td><%=EMPTY %></td><%
			}
			if(canEdit){
				%><td><a href="./editmember.do?<%=AppConstants.VY_ID %>=<%=rec.getVyId() %>" title="Edit" ><%=rec.getVyId() %></a></td><%
			}else{
				%><td><%=rec.getVyId() %></td><%
			}
			
			%>
			<td><%=rec.getFirstName()!=null? rec.getFirstName() : EMPTY %></td>
			<td><%=rec.getMiddleName()!=null?rec.getMiddleName() : EMPTY %></td>
			<td><%=rec.getLastName()!=null? rec.getLastName() : EMPTY %></td>
			<td><%=rec.getPmtCity()!=null?rec.getPmtCity(): EMPTY %></td>
			<td><%=rec.getPmtDistrictOrCounty()!=null?rec.getPmtDistrictOrCounty() : EMPTY %></td>
			<td><%=rec.getPmtStateOrRegion()!=null?rec.getPmtStateOrRegion() : EMPTY %></td>
			<td><%=rec.getPmtCountry()!=null?rec.getPmtCountry() : EMPTY %></td>
			<% if(rec.getRefVyId() != null) { %>
				<td><a href="./editmember.do?mode=VIEW&<%=AppConstants.VY_ID %>=<%=rec.getRefVyId() %>" title="View" target="_blank"><%=rec.getRefVyId() %></a></td>
			<% } else { %>
				<td><%=EMPTY %></td>
			<% } %> 
			<td><%=rec.getFamilyVyId()!=null?rec.getFamilyVyId() : EMPTY %></td>
			<td><%=rec.getFamilyRefType()!=null?rec.getFamilyRefType() : EMPTY %></td>
			<% if(rec.getDayOfBirth() != null && rec.getMonthOfBirth() != null && rec.getYearOfBirth() != null) { %>
				<td><%=(rec.getDayOfBirth().toString()+"/"+rec.getMonthOfBirth().toString()+"/"+rec.getYearOfBirth().toString()) %></td>
			<% } else { %>
				<td><%=EMPTY %></td>
			<% } %> 
			<td><%=rec.getPhoneNumber()!=null?rec.getPhoneNumber() : EMPTY %></td>
			<td><%=rec.getEmail()!=null?rec.getEmail() : EMPTY %></td>
			</tr>
			<%
  		}
	}
	else if(request.getAttribute(AppConstants.RESULT+"1") != null){
  		List<ViewVyMemberSubscriptionDO> results = (List<ViewVyMemberSubscriptionDO>)request.getAttribute(AppConstants.RESULT+"1");
  		int idx=0;  		
 		for(ViewVyMemberSubscriptionDO rec : results){
 			%><tr><%
			if(canDelete){
				%><td><input type="checkbox" name="members" value="<%=rec.getVyId() %>" /></td> <%
			}else{
				%><td><%=EMPTY %></td><%
			}
			if(rec.getIsDeleted()){
				%><td><img src="./images/iconError_16x16.gif" border="0" /></td> <%
			}else{
				%><td><%=EMPTY %></td><%
			}
			if(canEdit){
				%><td><a href="./editmember.do?<%=AppConstants.VY_ID %>=<%=rec.getVyId() %>" title="Edit" ><%=rec.getVyId() %></a></td><%
			}else{
				%><td><%=rec.getVyId() %></td><%
			}
			
			%>
			<td><%=rec.getFirstName()!=null? rec.getFirstName() : EMPTY %></td>
			<td><%=rec.getMiddleName()!=null?rec.getMiddleName() : EMPTY %></td>
			<td><%=rec.getLastName()!=null? rec.getLastName() : EMPTY %></td>
			<td><%=rec.getPrtCity()!=null?rec.getPrtCity(): EMPTY %></td>
			<td><%=rec.getPrtDistrictOrCounty()!=null?rec.getPrtDistrictOrCounty() : EMPTY %></td>
			<td><%=rec.getPrtStateOrRegion()!=null?rec.getPrtStateOrRegion() : EMPTY %></td>
			<td><%=rec.getPrtCountry()!=null?rec.getPrtCountry() : EMPTY %></td>
			<% if(rec.getRefVyId() != null) { %>
				<td><a href="./editmember.do?mode=VIEW&<%=AppConstants.VY_ID %>=<%=rec.getRefVyId() %>" title="View" target="_blank"><%=rec.getRefVyId() %></a></td>
			<% } else { %>
				<td><%=EMPTY %></td>
			<% } %> 
			<td><%=rec.getFamilyVyId()!=null?rec.getFamilyVyId() : EMPTY %></td>
			<td><%=rec.getFamilyRefType()!=null?rec.getFamilyRefType() : EMPTY %></td>
			<% if(rec.getDayOfBirth() != null && rec.getMonthOfBirth() != null && rec.getYearOfBirth() != null) { %>
				<td><%=(rec.getDayOfBirth().toString()+"/"+rec.getMonthOfBirth().toString()+"/"+rec.getYearOfBirth().toString()) %></td>
			<% } else { %>
				<td><%=EMPTY %></td>
			<% } %> 
			<td><%=rec.getPhoneNumber()!=null?rec.getPhoneNumber() : EMPTY %></td>
			<td><%=rec.getEmail()!=null?rec.getEmail() : EMPTY %></td>
			</tr>
			<%
	 	}
  	}else{
  		%><tr><td colspan="15"><%=RESOURCE.getString("NO_RECORDS") %></td></tr><%
  	}
  %>
  </tbody>
  </table>
 </div>
</form>
<script>

	function executeDelete() {
		//Use Ajax
	}

	var metaSvc = new MetaService();
	var f2 = function(){ executeDelete(); };

//	attachLangSupport("<%=ActionCtx.ctx().getLang()%>","mntnMemberForm");
//	attachLangSupport(['hindiAddress','regionalLangName']);
	
	function getMetadata(req) {
		metaSvc.getMeta("COUNTRY_META_SERVICE", req, {"country": "country", "district": "districtOrCounty", "state":"stateOrRegion", "city":"city"});
	}
//	function districtChange(){
//		getMetadata("COUNTRY="+document.getElementById("country").value+"&STATE="+document.getElementById("stateOrRegion").value+"&DISTRICT="+document.getElementById("districtOrCounty").value);
//	}
	function countryChange(){
		getMetadata("QUERY=STATE&COUNTRY="+document.getElementById("country").value);
	}
	function stateChange(){
		getMetadata("QUERY=CITY&COUNTRY="+document.getElementById("country").value+"&STATE="+document.getElementById("stateOrRegion").value);
	}
	addEvent('country', 'change', function(){ countryChange(); });
	addEvent('stateOrRegion', 'change', function(){ stateChange(); });
//	addEvent('districtOrCounty', 'change', function(){ districtChange(); });
//	countryChange();

	function groupPrintLabel(){
		var vals = getCheckedValues("members");
		if(vals.length == 0){
			alert("Please select at lease one member");
		}else{
			var url = "./addGroupPrintLabel.do?ops=add";
			for(var i in vals){
				url += "&subId="+ vals[i];
			}
			var gpl = window.open(url,"WinGroupPrintLabel","toolbars=0,location=0,height=600,width=800,resizable=1,scrollbars=1");
			gpl.focus();
		}
	}

</script>

</body> 
</html>
     
      
    
